package net.sansi.v3correctserver.config.matrixloader;

import lombok.extern.slf4j.Slf4j;
import net.sansi.v3correctserver.exception.ServiceException;

import java.nio.ByteBuffer;

/**
 * Created by Fang
 * create time : 2024/11/8
 * IDE : IntelliJ IDEA
 * <p>
 * int 类型矩阵文件转换器
 */
@Slf4j
public class IntegerMatrixFileLoader extends MatrixFileLoaderBase<Integer> {

    public IntegerMatrixFileLoader() {
        super(1);
    }

    @Override
    int getItemSize(Integer item) {
        return 1;
    }

    @Override
    int getItemBufferSize(Integer item) {
        return Integer.BYTES;
    }

    @Override
    int getItemBufferSize(int len) {
        return Integer.BYTES;
    }

    @Override
    void saveItemBuffer(ByteBuffer buffer, Integer item) {
        if (item == null) throw new ServiceException("整形矩阵内容中存在空置");
        buffer.putInt(item);
    }

    @Override
    Integer readItemBuffer(ByteBuffer buffer, int size) throws Exception {
        return buffer.getInt();
    }
}
